home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Utilities / Post / Source / ProcessARexx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-03  |  9.8 KB  |  484 lines

  1. #include "PostPre.h"
  2. #include "Global.h"
  3. #include    "PostWin.h"
  4.  
  5. struct RDArgs my_rdargs;
  6.  
  7. /*
  8.  * The strings in this program
  9.  */
  10. static char *strings[]=
  11. {
  12.     "Window already open",                                                    /* STR_ID_WINDOW_OPEN    */
  13.     "Window already closed",                                                /* STR_ID_WINDOW_CLOSE    */
  14.     "Window is not open",                                                    /* STR_ID_WINDOW_NONE    */
  15.     "ps-file is not conforming!",                                            /* STR_ID_PSFILE            */
  16.     "interpreter is not paused",                                            /* STR_ID_PAUSED            */
  17.     "Argument error to command %s",                                        /* STR_ID_ARGUMENT        */
  18.     "you are already on this page",                                        /* STR_ID_PAGE_OK            */
  19.     "you are already on the first page",                                /* STR_ID_PAGE_FIRST        */
  20.     "page-number too high, gone to last page",                        /* STR_ID_PAGE_HIGH        */
  21.     "page-number too low, gone to first page",                        /* STR_ID_PAGE_LOW        */
  22.     "interpreter is not running",                                            /* STR_ID_RUNNING            */
  23.     "no command or command string too long",                            /* STR_ID_STRING            */
  24.     "can't quit or clear during startup or interactive",            /* STR_ID_QUIT                */
  25.     "the current displaymode does not support enough colors!",    /* OPT_COLORS                */
  26.     "error during initiation",                                                /*    OPT_CREATE                */
  27.     "Can't obtain needed Pens!",                                            /* OPT_PENS                    */
  28. };
  29.  
  30. static    char    *cBuf, *nextchar, *error=NULL, *result=NULL, empty[]="";
  31. static    long    errlevel=0;
  32.  
  33.  
  34. void ProcessARexx(void)
  35. {
  36.     char    errorstr[256], helpstr[256], arg0[256], varname[30], *dummy;
  37.     int    next_page_number, err_id;
  38.     int    left = 0, top = 0, width = 0, height = 0;
  39.  
  40.     errlevel = 0;
  41.     error = NULL;
  42.     result = NULL;
  43.  
  44.     if(strlen(ARG0(rmsg)) == 0 || strlen(ARG0(rmsg)) > 255)
  45.     {
  46.         error=strings[STR_ID_STRING];
  47.         errlevel=10;
  48.         SetARexxLastError(RexxStuff,rmsg,error);
  49.         ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
  50.         rmsg = NULL;
  51.         return;
  52.     }
  53.     else
  54.     {
  55.         strcpy(arg0, ARG0(rmsg));
  56.     }
  57.  
  58.     cBuf = strtok(arg0, " ,");
  59.     nextchar = strtok(NULL, "");
  60.     if(nextchar == NULL) nextchar = empty;
  61.     if (!stricmp("OPENWINDOW",cBuf))
  62.     {
  63.         if (OutputWnd)
  64.         {
  65.             error=strings[STR_ID_WINDOW_OPEN];
  66.             errlevel=5;
  67.         }
  68.         else
  69.         {
  70.             openwindow();
  71.             do_blit();
  72.         }
  73.     }
  74.     else if (!stricmp("CLOSEWINDOW",cBuf))
  75.     {
  76.         if (OutputWnd == NULL)
  77.         {
  78.             error=strings[STR_ID_WINDOW_CLOSE];
  79.             errlevel=5;
  80.         }
  81.         else
  82.         {
  83.             closewindow();
  84.         }
  85.     }
  86.     else if (!stricmp("WINDOWTOFRONT",cBuf))
  87.     {
  88.         if (OutputWnd == NULL)
  89.         {
  90.             error=strings[STR_ID_WINDOW_NONE];
  91.             errlevel=5;
  92.         }
  93.         else
  94.         {
  95.             WindowToFront(OutputWnd);
  96.         }
  97.     }
  98.     else if (!stricmp("WINDOWTOBACK",cBuf))
  99.     {
  100.         if (OutputWnd == NULL)
  101.         {
  102.             error=strings[STR_ID_WINDOW_NONE];
  103.             errlevel=5;
  104.         }
  105.         else
  106.         {
  107.             WindowToBack(OutputWnd);
  108.         }
  109.     }
  110.     else if (!stricmp("ACTIVATEWINDOW",cBuf))
  111.     {
  112.         if (OutputWnd == NULL)
  113.         {
  114.             error=strings[STR_ID_WINDOW_NONE];
  115.             errlevel=5;
  116.         }
  117.         else
  118.         {
  119.             ActivateWindow(OutputWnd);
  120.         }
  121.     }
  122.     else if (!stricmp("SCREENTOFRONT",cBuf))
  123.     {
  124.         ScreenToFront(Options.Screen.custscreen ? custscreen : pubscrcontext.pubscreen);
  125.     }
  126.     else if (!stricmp("SCREENTOBACK",cBuf))
  127.     {
  128.         ScreenToBack(Options.Screen.custscreen ? custscreen : pubscrcontext.pubscreen);
  129.     }
  130.     else if (!stricmp("ZIPWINDOW",cBuf))
  131.     {
  132.         if (OutputWnd == NULL)
  133.         {
  134.             error=strings[STR_ID_WINDOW_NONE];
  135.             errlevel=5;
  136.         }
  137.         else
  138.         {
  139.             blit_to_window = FALSE;
  140.             ZipWindow(OutputWnd);
  141.             blit_to_window = TRUE;
  142.         }
  143.     }
  144.     else if (!stricmp("CHANGEWINDOWBOX",cBuf))
  145.     {
  146.         if (OutputWnd == NULL)
  147.         {
  148.             error=strings[STR_ID_WINDOW_NONE];
  149.             errlevel=5;
  150.         }
  151.         else if(*nextchar && (sscanf(nextchar, "%d %d %d %d", &left, &top, &width, &height) == 4))
  152.         {
  153.             blit_to_window = FALSE;
  154.             ChangeWindowBox(OutputWnd, left, top, width, height);
  155.             blit_to_window = TRUE;
  156.         }
  157.         else
  158.         {
  159.             errlevel=10;
  160.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "CHANGEWINDOWBOX");
  161.             error=errorstr;
  162.         }
  163.     }
  164.     else if (!stricmp("LEFT",cBuf))
  165.     {
  166.         if (OutputWnd == NULL)
  167.         {
  168.             error=strings[STR_ID_WINDOW_NONE];
  169.             errlevel=5;
  170.         }
  171.         else if(*nextchar && sscanf(nextchar, "%d", &left))
  172.         {
  173.             do_gadgets(GAD_LEFT, left);
  174.         }
  175.         else
  176.         {
  177.             errlevel=10;
  178.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "LEFT");
  179.             error=errorstr;
  180.         }
  181.     }
  182.     else if (!stricmp("RIGHT",cBuf))
  183.     {
  184.         if (OutputWnd == NULL)
  185.         {
  186.             error=strings[STR_ID_WINDOW_NONE];
  187.             errlevel=5;
  188.         }
  189.         else if(*nextchar && sscanf(nextchar, "%d", &left))
  190.         {
  191.             do_gadgets(GAD_RIGHT, left);
  192.         }
  193.         else
  194.         {
  195.             errlevel=10;
  196.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "RIGHT");
  197.             error=errorstr;
  198.         }
  199.     }
  200.     else if (!stricmp("UP",cBuf))
  201.     {
  202.         if (OutputWnd == NULL)
  203.         {
  204.             error=strings[STR_ID_WINDOW_NONE];
  205.             errlevel=5;
  206.         }
  207.         else if(*nextchar && sscanf(nextchar, "%d", &left))
  208.         {
  209.             do_gadgets(GAD_UP, left);
  210.         }
  211.         else
  212.         {
  213.             errlevel=10;
  214.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "UP");
  215.             error=errorstr;
  216.         }
  217.     }
  218.     else if (!stricmp("DOWN",cBuf))
  219.     {
  220.         if (OutputWnd == NULL)
  221.         {
  222.             error=strings[STR_ID_WINDOW_NONE];
  223.             errlevel=5;
  224.         }
  225.         else if(*nextchar && sscanf(nextchar, "%d", &left))
  226.         {
  227.             do_gadgets(GAD_DOWN, left);
  228.         }
  229.         else
  230.         {
  231.             errlevel=10;
  232.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "DOWN");
  233.             error=errorstr;
  234.         }
  235.     }
  236.     else if (!stricmp("CLEAR",cBuf))
  237.     {
  238.         if(interactive || startup)
  239.         {
  240.             errlevel = 5;
  241.             error = strings[STR_ID_QUIT];
  242.         }
  243.         else MenuClear();
  244.     }
  245.     else if (!stricmp("OKMSG",cBuf))
  246.     {
  247.         okmsg(nextchar);
  248.     }
  249.     else if (!stricmp("OPEN",cBuf) || !stricmp("LOADFONT",cBuf))
  250.     {
  251.         strcpy(Options.lastfile, nextchar);
  252.         sendfile(PSACTFILE);
  253.     }
  254.     else if (!stricmp("RUN",cBuf))
  255.     {
  256.         strcpy(Options.lastfile, nextchar);
  257.         sendfile(PSACTRUN);
  258.     }
  259.     else if (!stricmp("NEXTPAGE",cBuf))
  260.     {
  261.         if (err_id = nextpage())
  262.         {
  263.             error=strings[err_id];
  264.             errlevel=5;
  265.         }
  266.     }
  267.     else if (!stricmp("PREVIOUSPAGE",cBuf))
  268.     {
  269.         if (err_id = previouspage())
  270.         {
  271.             error=strings[err_id];
  272.             errlevel=5;
  273.         }
  274.     }
  275.     else if (!stricmp("GOTOPAGE",cBuf))
  276.     {
  277.         if(*nextchar && sscanf(nextchar, "%d", &next_page_number))
  278.         {
  279.             if(running && paused)
  280.             {
  281.                 if(number_of_pages)
  282.                 {
  283.                     if(next_page_number < 1)
  284.                     {
  285.                         next_page_number = 1;
  286.                         errlevel = 5;
  287.                         error = strings[STR_ID_PAGE_LOW];
  288.                     }
  289.                     else if (next_page_number > number_of_pages)
  290.                     {
  291.                         next_page_number = number_of_pages;
  292.                         errlevel = 5;
  293.                         error = strings[STR_ID_PAGE_HIGH];
  294.                     }
  295.                     if (err_id = gotopage(next_page_number))
  296.                     {
  297.                         errlevel = 5;
  298.                         error = strings[err_id];
  299.                     }
  300.                 }
  301.                 else
  302.                 {
  303.                     errlevel = 5;
  304.                     error = strings[STR_ID_PSFILE];
  305.                 }
  306.             }
  307.             else
  308.             {
  309.                 errlevel = 5;
  310.                 error = strings[STR_ID_PAUSED];
  311.             }
  312.         }
  313.         else
  314.         {
  315.             errlevel = 10;
  316.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "GOTOPAGE");
  317.             error=errorstr;
  318.         }
  319.     }
  320.     else if (!stricmp("QUIT",cBuf))
  321.     {
  322.         if(interactive || startup)
  323.         {
  324.             errlevel = 5;
  325.             error = strings[STR_ID_QUIT];
  326.         }
  327.         else
  328.         {
  329.             if (error)
  330.             {
  331.                 SetARexxLastError(RexxStuff,rmsg,error);
  332.             }
  333.             ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
  334.             rmsg = NULL;
  335.             errorende();                        
  336.             exit(0);
  337.         }
  338.     }
  339.     else if (!stricmp("GETSTATUS",cBuf))
  340.     {
  341.         if(interactive) dummy = titleinter;
  342.         else if(arexx) dummy = titlearexx;
  343.         else if(paused) dummy = titlepaused;
  344.         else if(startup) dummy = titlestart;
  345.         else if(running) dummy = titlerunning;
  346.         else dummy = titlewait;
  347.         sprintf(varname, "%s.STATUS", AREXXPORTNAME);
  348.         SetARexxVariable(RexxStuff, rmsg, varname, dummy);
  349.         sprintf(varname, "%s.ERROR", AREXXPORTNAME);
  350.         if(errstr) SetARexxVariable(RexxStuff, rmsg, varname, errstr);
  351.         else SetARexxVariable(RexxStuff, rmsg, varname, "No Error");
  352.         sprintf(helpstr, "%d", retcode);
  353.         sprintf(varname, "%s.ERRORNUM", AREXXPORTNAME);
  354.         SetARexxVariable(RexxStuff, rmsg, varname, helpstr);
  355.     }
  356.     else if (!stricmp("INTERRUPT",cBuf))
  357.     {
  358.         if(running && !paused) PSsignalint(arec, 1);
  359.         else
  360.         {
  361.             error=strings[STR_ID_RUNNING];
  362.             errlevel=5;
  363.         }
  364.     }
  365.     else if (!stricmp("KILL",cBuf))
  366.     {
  367.         if(running && !paused) PSsignalint(arec, 2);
  368.         else
  369.         {
  370.             error=strings[STR_ID_RUNNING];
  371.             errlevel=5;
  372.         }
  373.     }
  374.     else if (!stricmp("SETOPTS",cBuf))
  375.     {
  376.         if(*nextchar)
  377.         {
  378.             struct    Options opts_bak;
  379.  
  380.             strcpy(helpstr, nextchar);
  381.             strcat(helpstr, "\n");
  382.             my_rdargs.RDA_Source.CS_Buffer = helpstr;
  383.             my_rdargs.RDA_Source.CS_Length = strlen(helpstr);
  384.             my_rdargs.RDA_Source.CS_CurChr = 0;
  385.             my_rdargs.RDA_DAList = 0;
  386.             my_rdargs.RDA_Buffer = NULL;
  387.             my_rdargs.RDA_BufSiz = 0;
  388.             my_rdargs.RDA_ExtHelp = NULL;
  389.             my_rdargs.RDA_Flags = 0;
  390.             copy_options(&opts_bak, &Options);
  391.             argwindow = FALSE;
  392.             if(parse(1, &my_rdargs))
  393.             {
  394.                 errlevel = 5;
  395.                 error = undobuff;
  396.             }
  397.             else
  398.             {
  399.                 copy_options(&TempOptions, &Options);
  400.                 copy_options(&Options, &opts_bak);
  401.                 if(errlevel = do_opts())
  402.                 {
  403.                     copy_options(&Options, &opts_bak);
  404.                     if(errlevel == OPT_CREATE || errlevel == OPT_PENS)
  405.                     {
  406.                         saveterminate();
  407.                         sendmenu(PSACTCREATE, 0, 0, 0, NULL, NULL);
  408.                         Wait(1L << create_signal);
  409.                         if(createerror)
  410.                         {                    
  411.                             errlevel = 20;
  412.                             SetARexxLastError(RexxStuff,rmsg,"can't activate old prefs");
  413.                             ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
  414.                             rmsg = NULL;
  415.                             errorende();                        
  416.                             exit(0);
  417.                         }
  418.                         if(errlevel == OPT_PENS)
  419.                         {
  420.                             openwindow();
  421.                             do_blit();
  422.                         }
  423.                         runstartupfiles();
  424.                     }
  425.                     error = strings[errlevel];
  426.                     errlevel = 10;
  427.                 }
  428.             }
  429.         }
  430.         else
  431.         {
  432.             errlevel=10;
  433.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "SETOPTS");
  434.             error=errorstr;
  435.         }
  436.     }
  437.     else if (!stricmp("CUSTOMSCREEN",cBuf))
  438.     {
  439.         do_screen();
  440.     }
  441.     else if (!stricmp("PUBSCREEN",cBuf))
  442.     {
  443.         if(*nextchar)
  444.         {
  445.             if(strlen(nextchar) > MAXPUBSCREENNAME)
  446.             {
  447.                 okmsg("pubscrn to long");
  448.             }
  449.             else
  450.             {
  451.                 strcpy(newpubscreenname, nextchar);
  452.                 if(errlevel = do_pubscreen())
  453.                 {
  454.                     error = strings[errlevel];
  455.                     errlevel = 10;
  456.                 }
  457.             }
  458.             
  459.         }
  460.         else
  461.         {
  462.             errlevel=10;
  463.             sprintf(errorstr, strings[STR_ID_ARGUMENT], "PUBSCREEN");
  464.             error=errorstr;
  465.         }
  466.     }
  467.     else
  468.     {
  469.         sendmenu(PSACTAREXX, 0, 0, 0, NULL, ARG0(rmsg));
  470.         return;
  471.     }
  472.  
  473.     if (error)
  474.     {
  475.         SetARexxLastError(RexxStuff,rmsg,error);
  476.     }
  477.     if(rmsg)
  478.     {
  479.         ReplyARexxMsg(RexxStuff,rmsg,result,errlevel);
  480.         rmsg = NULL;
  481.     }
  482.     return;
  483. }
  484.